#include "Dialogs.h"

static Dialogs *diag;

void CALLBACK Dialogs::WndValueProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
	diag->OnWndValueProc(hWnd, msg, wParam, lParam);
}

LRESULT Dialogs::OnWndValueProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
	//TCHAR buff[20];
	switch(msg) {
		/*case WM_MOVING:
			if(_parentHandler != 0)
				InvalidateRect(_parentHandler, NULL, false);
			break;*/
		case WM_INITDIALOG:
	/*		if(res != 0.0f) {
				//wpisz w pole textowe wartosc
				swprintf_s(buff, 20, L"%f", res);
				SetDlgItemText(hwnd, IDC_EDITBOX, buff);
			}*/
			if(_text != NULL)
				SetWindowText(hWnd, _text);
			break;
		case WM_COMMAND:
			switch(wParam) {
				case IDOK:
					/*if(0 < GetDlgItemText(hwnd, IDC_EDITBOX, buff, 20)) {
						res = (float)_wtof(buff);
					}*/
					_success = true;
				case IDCANCEL:
					EndDialog(hWnd, 0);
					return TRUE;
			}
			break;
		default:
			return FALSE;
	}
	return TRUE;
}

void CALLBACK Dialogs::WndVector3Proc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
	diag->OnWndValueProc(hWnd, msg, wParam, lParam);
}

void CALLBACK Dialogs::WndVector4Proc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
	diag->OnWndValueProc(hWnd, msg, wParam, lParam);
}

bool Dialogs::GetFloatValue(WCHAR *txt)
{
	_text = txt;
	_success = false;
	DialogBox(_inst, MAKEINTRESOURCE(IDD_FLOATVALUE),
		_parentHandler, (DLGPROC) WndValueProc);
	return _success;
}

bool Dialogs::GetFloatVector3(WCHAR *txt)
{
	_text = txt;
	_success = false;
	DialogBox(_inst, MAKEINTRESOURCE(IDD_FLOATVALUE),
		_parentHandler, (DLGPROC) WndVector3Proc);
	return _success;
}

bool Dialogs::GetFloatVector4(WCHAR *txt)
{
	_text = txt;
	_success = false;
	DialogBox(_inst, MAKEINTRESOURCE(IDD_FLOATVALUE),
		_parentHandler, (DLGPROC) WndVector4Proc);
	return _success;
}

bool Dialogs::OpenFileDialog(WCHAR* ext)
{
	OPENFILENAME ofn;
	ZeroMemory(&ofn, sizeof(ofn));
	ofn.lStructSize = sizeof(ofn);
	ofn.nMaxFile = MAX_PATH_SIZE;
	ofn.lpstrFile = _path;
	ofn.lpstrDefExt = ext;
	ofn.Flags = OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
	if(GetOpenFileName(&ofn))		
		return true;
	return false;
}

Dialogs::Dialogs(HWND parent, HINSTANCE instance)
{
	Init(parent, instance);
	_text = NULL;
}

void Dialogs::Init(HWND parent, HINSTANCE instance)
{
	_parentHandler = parent;
	_inst = instance;
	ZeroMemory(_path, MAX_PATH_SIZE * sizeof(WCHAR));
}

Dialogs::~Dialogs(void)
{
}

